/*
 * TowerGreenOne.java
 *
 * Created on November 24, 2007, 3:34 PM
 *
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package hextd.tower;

import hextd.Constants;
import hextd.hex.HexTile;
import hextd.creep.HexTDCreep;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author hylke
 */
public class TowerGreenOne extends TowerBase {

	public static final Map<String, Long> price = new HashMap<String, Long>();

	static {
		price.put(Constants.RESOURCE_CREDIT, 100l);
	}
	public static int damage = 10;
	public static double range = 4f;
	public static String name = "Green One";
	//
	private HexTDCreep fireAt = null;
	private Constants.COLOR damageColor = Constants.COLOR.GREEN;
	private Point2D.Double tempTargetPLoc = new Point2D.Double();

	/** Creates a new instance of TowerGreenOne */
	public TowerGreenOne() {
		super(FactoryTower.type.greenOne, price, damage, range);
		lineColor = Color.GREEN;
		hexInfluence = 1;
	}

	@Override
	public void runTick(int gameTime) {
		if (!lock) {
			fireAt = null;
		}
		HexTDCreep enemy = findEnemy(fireAt, false);

		fireAt = enemy;
		if (enemy != null) {
			enemy.doDamage(getOwner(), damageCurrent, damageColor);
		}
	}

	@Override
	public String getStatusString() {
		String retString = "";
		retString += "<h1>Green Tower 1</h1>"
				+ "<p>"
				+ "<b>Level:</b> " + (1 + level) + "<br>\n"
				+ "<b>Damage:</b> " + damageText + "<br>\n"
				+ "<b>Range:</b> " + rangeText + "<br>"
				+ "</p>\n";
		return retString;
	}

	@Override
	public String getDescription() {
		String retString = "";
		retString += "<h1>Green Tower 1</h1>"
				+ "<p>"
				+ "Basic tower with one weak laser. Strong against green enemies, very weak against red enemies.</p>"
				+ "<p>"
				+ "<b>Price:</b> " + TowerGreenOne.price + "<br>"
				+ "<b>Damage:</b> " + damageCurrent + "<br>"
				+ "<b>Range:</b> " + TowerGreenOne.form.format(rangeCurrent) + "<br>"
				+ "<b>Refire rate:</b> 20/s"
				+ "</p>";
		return retString;
	}

	@Override
	protected void generateShapes() {
		double width = HexTile.relativeHexWidth;
		int shapeCount = 5;
		shapes = new Shape[shapeCount];
		shapes[0] = new Ellipse2D.Double(-0.4 * paintScale, -0.4 * paintScale, 0.8 * paintScale, 0.8 * paintScale);
		shapes[1] = new Line2D.Double(0, 0.4 * paintScale, 0, paintScale);
		shapes[2] = new Line2D.Double(-0.4 * width, -0.5 * 0.4 * paintScale, -width, -0.5 * paintScale);
		shapes[3] = new Line2D.Double(0.4 * width, -0.5 * 0.4 * paintScale, width, -0.5 * paintScale);
		shapes[4] = new Ellipse2D.Double(-1.0 * strokeScale, -1.0 * strokeScale, 2.0 * strokeScale, 2.0 * strokeScale);

		shapeAction = new int[shapeCount];
		shapeAction[0] = 1;
		shapeAction[1] = 1;
		shapeAction[2] = 1;
		shapeAction[3] = 1;
		shapeAction[4] = 1;

		shapeColor = new Color[shapeCount];
		shapeColor[0] = lineColor;
		shapeColor[1] = lineColor;
		shapeColor[2] = lineColor;
		shapeColor[3] = lineColor;
		shapeColor[4] = lineColor;

		strokes = new Stroke[shapeCount];
		strokes[0] = new BasicStroke(2.0f * strokeScale, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
		strokes[1] = strokes[0];
		strokes[2] = strokes[0];
		strokes[3] = strokes[0];
		strokes[4] = strokes[0];
	}

	@Override
	public void paintEffects(Graphics2D g2, int gameTime) {
		Stroke defaultStroke = g2.getStroke();

		HexTDCreep t = fireAt;
		if (t != null) {
			g2.setColor(lineColor);
			t.getPaintLocation(tempTargetPLoc);
			g2.draw(new Line2D.Double(
					paintLocation.x,
					paintLocation.y,
					tempTargetPLoc.x + ((Math.random() - 0.5) * paintScale / 10f),
					tempTargetPLoc.y + ((Math.random() - 0.5) * paintScale / 10f)));
		}

		g2.setStroke(defaultStroke);
	}
}
